package com.controller;

import com.dto.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by iss on 17/6/9.
 */
@Controller
@RequestMapping
public class TestController {


    @RequestMapping(value = "/a")
    @ResponseBody
    public Object a() {
        return "{\"name\":\"喻杰\"}";
    }

    @ResponseBody
    @RequestMapping("/b")
    public Object b() {
        return new User("喻杰");
    }

    @ResponseBody
    @RequestMapping("/c")
    public Object c() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", "喻杰");
        return map;
    }

    @RequestMapping(value = "/d")
    public void d(HttpServletResponse response) {
        try {
            response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write(  "{\"name\":\"喻杰\"}");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @RequestMapping("/index")
    public Object index() {
        return "index";
    }
}
